﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKPresentation.CommonUnit;
using YJKPresentation.Utils;

namespace YJKPresentation.CrossFloor
{
	public class ManualCopyEntitiesManager
	{
		public ManualCopyEntitiesManager(ExternalCommandData cmdData, Autodesk.Revit.DB.View destinationView, Transform transform)
		{
			this.m_Revit = cmdData;
			this.m_SourceView = this.m_Revit.Application.ActiveUIDocument.ActiveView;
			this.m_DestinationView = destinationView;
			this.m_Transform = transform;
			XYZ newDirection = Locator.GetNewDirection(XYZ.BasisX, this.m_Transform);
			XYZ newDirection2 = Locator.GetNewDirection(XYZ.BasisY, this.m_Transform);
			double angle = Geometry.getAngle(XYZ.Zero, newDirection);
			double angle2 = Geometry.getAngle(XYZ.Zero, newDirection2);
			if (Geometry.IsEqual(Geometry.BetweenTheAngles(angle, angle2, true), Math.PI*.5))
			{
				this.m_IsMirrored = false;
			}
			else
			{
				this.m_IsMirrored = true;
			}
			this.m_ParasiticEntCopier = new ParasiticEntitiesCopier(this.m_Revit, this.m_DestinationView, this.m_Transform, this.m_IsMirrored, this.m_Tolerance);
		}

		public void Copy(List<FamilyInstance> baseOnWallParasiticEntitiesList, List<FamilyInstance> baseOnCeilingParasticElements, List<FamilyInstance> baseOnSurfaceParasiticEntitiesList)
		{
			this.CopyParasiticEntities(baseOnWallParasiticEntitiesList, ParasiticEntitiesCopier.BaseOnType.BASEON_WALL);
			this.CopyParasiticEntities(baseOnCeilingParasticElements, ParasiticEntitiesCopier.BaseOnType.BASEON_CEILING);
			this.CopyParasiticEntities(baseOnSurfaceParasiticEntitiesList, ParasiticEntitiesCopier.BaseOnType.BASEON_SURFACE);
		}

		private void CopyParasiticEntities(List<FamilyInstance> parasiticEntitiesList, ParasiticEntitiesCopier.BaseOnType baseOnType)
		{
			foreach (FamilyInstance parEnt in parasiticEntitiesList)
			{
				try
				{
					this.m_ParasiticEntCopier.CopyParasiticEntity(parEnt, baseOnType);
				}
				catch (Exception ex)
				{
					string message = ex.Message;
				}
			}
		}

		private ExternalCommandData m_Revit;

		private Autodesk.Revit.DB.View m_SourceView;

		private Autodesk.Revit.DB.View m_DestinationView;

		private double m_Tolerance = Common.MMToFeet(500.0);

		private Transform m_Transform;

		private bool m_IsMirrored;

		private ParasiticEntitiesCopier m_ParasiticEntCopier;
	}
}
